#ifndef __IMAGEMANAGER_H__
#define __IMAGEMANAGER_H__

#include "Common.h"
#include <map>
#include <string>
#include "Utils/Singleton.h"
#include "Utils/Manager.h"
#include "Imaging/Image.h"

namespace RayFrame
{

  class ImageCodec;

  enum ImageFileFormat
  {
    IFF_UNKNOWN = -1,
    IFF_BMP    = 0,
    IFF_ICO    = 1,
    IFF_JPEG  = 2,
    IFF_JNG    = 3,
    IFF_KOALA  = 4,
    IFF_LBM    = 5,
    IFF_IFF = IFF_LBM,
    IFF_MNG    = 6,
    IFF_PBM    = 7,
    IFF_PBMRAW  = 8,
    IFF_PCD    = 9,
    IFF_PCX    = 10,
    IFF_PGM    = 11,
    IFF_PGMRAW  = 12,
    IFF_PNG    = 13,
    IFF_PPM    = 14,
    IFF_PPMRAW  = 15,
    IFF_RAS    = 16,
    IFF_TARGA  = 17,
    IFF_TIFF  = 18,
    IFF_WBMP  = 19,
    IFF_PSD    = 20,
    IFF_CUT    = 21,
    IFF_XBM    = 22,
    IFF_XPM    = 23,
    IFF_DDS    = 24,
    IFF_GIF     = 25,
    IFF_HDR    = 26,
    IFF_FAXG3  = 27,
    IFF_SGI    = 28,
    IFF_EXR    = 29,
    IFF_J2K    = 30,
    IFF_JP2    = 31,
    IFF_PFM    = 32,
    IFF_PICT  = 33,
    IFF_RAW    = 34
  };
 
  /// Class used to load, destroy and manager all images
  class ImageManager: public Singleton<ImageManager>, public Manager<Image>
  {
  protected:
    STRING    m_crtImage;
  protected:
    virtual bool InitLibrary(){ return false; };
    virtual bool DestroyLibrary(){ return false; };
  public:
    enum ImageFilter
    {
      FILTER_GAUSSIAN,
    };

    ImageManager()
    {
      InitLibrary();
    };

    virtual ~ImageManager()
    {
      DestroyLibrary();
    };

    DLL_DECLARE Image* CreateImage(STRING imageName, unsigned width, unsigned height, PixelFormat iff);

    /// Load a image from file
    DLL_DECLARE virtual Image* LoadFromFile(STRING imageName, STRING filename);

    /// Load a default image file with "REPLACE ME" in it.
    DLL_DECLARE Image* GetDefaultImage();

    /// Save a image to file
    DLL_DECLARE virtual bool SaveToFile(Image* image, STRING filename, ImageFileFormat iff = IFF_BMP);

    DLL_DECLARE static int GetNumElemBytes( PixelFormat pf );
    DLL_DECLARE static int GetComponentCount( PixelFormat pf);

    void SetCurrentImage(STRING imageName){ m_crtImage = imageName; };

    DECL_SINGLETON_DLL(ImageManager);
  };
}

#endif /* _IMAGEMANAGER_H_ */
